<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>获取当前的PHP版本</title>
 </head>
 <body class="docs"><div id="layout">
  <div id="layout-content"><div id="function.phpversion" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">phpversion</h1>
  <p class="verinfo">(PHP 4, PHP 5, PHP 7)</p><p class="refpurpose"><span class="refname">phpversion</span> &mdash; <span class="dc-title">获取当前的PHP版本</span></p>

 </div>
 
 <div class="refsect1 description" id="refsect1-function.phpversion-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>phpversion</strong></span>
    ([ <span class="methodparam"><span class="type">string</span> <code class="parameter">$extension</code></span>
  ] ) : <span class="type">string</span></div>

  <p class="para rdfs-comment">
   返回了包含当前运行 PHP 解释器或扩展版本信息的 string。
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.phpversion-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>

    
     <dt>
<code class="parameter">extension</code></dt>

     <dd>

      <p class="para">
       可选的扩展名。
      </p>
     </dd>

    
   </dl>

  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.phpversion-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   如果指定了可选参数 <code class="parameter">extension</code>，<span class="function"><strong>phpversion()</strong></span>会返回该扩展的版本。
   如果没有对应的版本信息，或者该扩展未启用，则返回 <strong><code>FALSE</code></strong>。
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.phpversion-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-528">
    <p><strong>Example #1 <span class="function"><strong>phpversion()</strong></span> 范例</strong></p>
    <div class="example-contents">
<div class="phpcode"><pre><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #FF8000">//&nbsp;prints&nbsp;e.g.&nbsp;'Current&nbsp;PHP&nbsp;version:&nbsp;4.1.1'<br /></span><span style="color: #007700">echo&nbsp;</span><span style="color: #DD0000">'Current&nbsp;PHP&nbsp;version:&nbsp;'&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #0000BB">phpversion</span><span style="color: #007700">();<br /><br /></span><span style="color: #FF8000">//&nbsp;prints&nbsp;e.g.&nbsp;'2.0'&nbsp;or&nbsp;nothing&nbsp;if&nbsp;the&nbsp;extension&nbsp;isn't&nbsp;enabled<br /></span><span style="color: #007700">echo&nbsp;</span><span style="color: #0000BB">phpversion</span><span style="color: #007700">(</span><span style="color: #DD0000">'tidy'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</pre></div>
    </div>

   </div>
  </p>
  <p class="para">
   <div class="example" id="example-529">
    <p><strong>Example #2 <strong><code>PHP_VERSION_ID</code></strong> 范例和用法</strong></p>
    <div class="example-contents">
<div class="phpcode"><pre><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #FF8000">//&nbsp;PHP_VERSION_ID&nbsp;自&nbsp;PHP&nbsp;5.2.7&nbsp;起有效，<br />//&nbsp;如果我们的版本低于该版本，则用以下代码来模拟&nbsp;<br /></span><span style="color: #007700">if&nbsp;(!</span><span style="color: #0000BB">defined</span><span style="color: #007700">(</span><span style="color: #DD0000">'PHP_VERSION_ID'</span><span style="color: #007700">))&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$version&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">explode</span><span style="color: #007700">(</span><span style="color: #DD0000">'.'</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">PHP_VERSION</span><span style="color: #007700">);<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">define</span><span style="color: #007700">(</span><span style="color: #DD0000">'PHP_VERSION_ID'</span><span style="color: #007700">,&nbsp;(</span><span style="color: #0000BB">$version</span><span style="color: #007700">[</span><span style="color: #0000BB">0</span><span style="color: #007700">]&nbsp;*&nbsp;</span><span style="color: #0000BB">10000&nbsp;</span><span style="color: #007700">+&nbsp;</span><span style="color: #0000BB">$version</span><span style="color: #007700">[</span><span style="color: #0000BB">1</span><span style="color: #007700">]&nbsp;*&nbsp;</span><span style="color: #0000BB">100&nbsp;</span><span style="color: #007700">+&nbsp;</span><span style="color: #0000BB">$version</span><span style="color: #007700">[</span><span style="color: #0000BB">2</span><span style="color: #007700">]));<br />}<br /><br /></span><span style="color: #FF8000">//&nbsp;PHP_VERSION_ID&nbsp;定义为一个数字，PHP&nbsp;版本越新，数字越大。<br />//&nbsp;它的定义是以下的表达式：<br />//<br />//&nbsp;$version_id&nbsp;=&nbsp;$major_version&nbsp;*&nbsp;10000&nbsp;+&nbsp;$minor_version&nbsp;*&nbsp;100&nbsp;+&nbsp;$release_version;<br />//<br />//&nbsp;现在我们可以通过&nbsp;PHP_VERSION_ID&nbsp;来检查&nbsp;PHP&nbsp;版本，<br />//&nbsp;而不用每次都必须用&nbsp;version_compare()&nbsp;来检查&nbsp;PHP&nbsp;是否支持某个功能。<br />//<br />//&nbsp;比如，我们在此可以定义一系列&nbsp;PHP_VERSION_*&nbsp;constants&nbsp;常量，<br />//&nbsp;而在&nbsp;5.2.7&nbsp;之前的版本并没有被定义。<br /><br /></span><span style="color: #007700">if&nbsp;(</span><span style="color: #0000BB">PHP_VERSION_ID&nbsp;</span><span style="color: #007700">&lt;&nbsp;</span><span style="color: #0000BB">50207</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">define</span><span style="color: #007700">(</span><span style="color: #DD0000">'PHP_MAJOR_VERSION'</span><span style="color: #007700">,&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$version</span><span style="color: #007700">[</span><span style="color: #0000BB">0</span><span style="color: #007700">]);<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">define</span><span style="color: #007700">(</span><span style="color: #DD0000">'PHP_MINOR_VERSION'</span><span style="color: #007700">,&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$version</span><span style="color: #007700">[</span><span style="color: #0000BB">1</span><span style="color: #007700">]);<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">define</span><span style="color: #007700">(</span><span style="color: #DD0000">'PHP_RELEASE_VERSION'</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$version</span><span style="color: #007700">[</span><span style="color: #0000BB">2</span><span style="color: #007700">]);<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">//&nbsp;等等，&nbsp;...<br /></span><span style="color: #007700">}<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</pre></div>
    </div>

   </div>
  </p>
 </div>


 <div class="refsect1 notes" id="refsect1-function.phpversion-notes">
  <h3 class="title">注释</h3>
  <blockquote class="note"><p><strong class="note">Note</strong>: 
   <p class="para">
    这些信息也存在于预定义常量 <strong><code>PHP_VERSION</code></strong>里。
    更多版本的信息可以使用常量 <strong><code>PHP_VERSION_*</code></strong>。
   </p>
  </p></blockquote>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.phpversion-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><a href="reserved.constants.html#reserved.constants.core" class="link">常量 PHP_VERSION</a></li>
    <li class="member"><span class="function"><a href="version_compare.html" class="function" rel="rdfs-seeAlso">version_compare()</a> - 对比两个「PHP 规范化」的版本数字字符串</span></li>
    <li class="member"><span class="function"><a href="phpinfo.html" class="function" rel="rdfs-seeAlso">phpinfo()</a> - 输出关于 PHP 配置的信息</span></li>
    <li class="member"><span class="function"><a href="phpcredits.html" class="function" rel="rdfs-seeAlso">phpcredits()</a> - 打印 PHP 贡献者名单</span></li>
    <li class="member"><span class="function"><a href="php_logo_guid.html" class="function" rel="rdfs-seeAlso">php_logo_guid()</a> - 获取 logo 的 guid</span></li>
    <li class="member"><span class="function"><a href="zend_version.html" class="function" rel="rdfs-seeAlso">zend_version()</a> - 获取当前 Zend 引擎的版本</span></li>
   </ul>
  </p>
 </div>


</div></div></div></body></html>